﻿@model int?
@using CSF.Utility.Mvc;
@using CSF.Products.Data;

@{
    IEnumerable<ProductCategory> categories = ViewBag.ProductCategories;
    if (categories != null && ViewData.ContainsKey("SelfId"))
    {
        int selfId = (int)ViewData["SelfId"];
        if (selfId > 0)
        {
            categories = categories.Where(p => p.Id != selfId);
        }
    }
    TreeBuilder<ProductCategory, int?> tree = new TreeBuilder<ProductCategory, int?>(categories,
        p => p.Id, p => p.ParentId,
        (p, isLeaf) => Html.RadioButton("", p.Id, (Model ?? 0) == p.Id).ToString() + "&nbsp;" + p.Name1,
        null);
}
@Html.RadioButton("", 0, Model == null)&nbsp;Top level
@if (categories != null)
{
    @Html.Raw(tree.ToString(new { @id = "cattree" }))
    <script type="text/javascript">
        $('#cattree').tree();
    </script>
}